package vlms.dao;

import java.sql.*;

import vlms.exception.MovieRecordCountException;

public class MovieRecordCountDAO {
	public MovieRecordCountDAO() {
	}

	public MovieRecordCount getRecordCount(Connection con)
			throws MovieRecordCountException {
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try {
			stmt = con.prepareStatement("SELECT COUNT(*) FROM MOVIE");
			rs = stmt.executeQuery();
			rs.next();
			MovieRecordCount vo = new MovieRecordCount();
			vo.setCount(rs.getInt(1));
			return vo;
		} catch (SQLException sqle) {
			throw new MovieRecordCountException(sqle);
		} catch (Exception e) {
			throw new MovieRecordCountException(e);
		}
	}

	public MovieRecordCount getRecordCount(Connection con, String whereClause)
			throws MovieRecordCountException {
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try {
			stmt = con.prepareStatement("SELECT COUNT(*) FROM MOVIE  "
					+ whereClause);
			rs = stmt.executeQuery();
			rs.next();
			MovieRecordCount vo = new MovieRecordCount();
			vo.setCount(rs.getInt(1));
			return vo;
		} catch (SQLException sqle) {
			throw new MovieRecordCountException(sqle);
		} catch (Exception e) {
			throw new MovieRecordCountException(e);
		}
	}
}
